package  
{
	import net.flashpunk.World;
	import net.flashpunk.FP;
	import net.flashpunk.graphics.Image;
	import net.flashpunk.graphics.Spritemap;
	import net.flashpunk.Sfx;
	import net.flashpunk.utils.Input;
	/**
	 * ...
	 * @author Donatello
	 */
	public class SeptScene extends World
	{
		[Embed(source = "sfx/carStarting.mp3")] public static const CAR:Class;
		private var car:Sfx = new Sfx(CAR);
		[Embed(source = "sfx/carStarting2.mp3")] public static const CAR2:Class;
		private var car2:Sfx = new Sfx(CAR2);
		
		[Embed(source = "img/final.png")]private const IMG_BACK:Class;
		private var imgBack:Image;
		
		[Embed(source = "img/bar.png")]private const BAR:Class;
		private var bar:Image = new Image(BAR);	
		
		private var time:Number = 0.0;
		private var textos:Boolean = false;
		private var agregada:Boolean = false;
		private var pressed:Boolean = false;
		private var counter:int = 0;
		private var lastX:Number;
		private var fuel:Vector.<Fuel>;
		private var fuelAux:Fuel;
		private var fuelTime:Number = 0.0;
		private var done:Boolean = false;
		
		public function SeptScene() 
		{
			
			imgBack = new Image(IMG_BACK);
			imgBack.x = 0;
			imgBack.y = 0;
			
			bar.x = 150;
			bar.y = 550;
			lastX = 150 + 5;
			
			add(new Dialog("Al salir, reconoci entre los atacantes a un miembro de la otra familia", 100, 300, 4, 300));
			
			fuel = new Vector.<Fuel>;
			
		
		}
		
		
		override public function update():void
		{
			time += FP.elapsed;
					
			if (time >= 4 && !textos )
			{
				add(new Dialog("Subi rapido al auto para seguirlo", 200, 300, 3, 300));
				time = 0.0;
				textos = true;
			}
			if (time > 3 && textos && !done)
			{
				fuelTime += FP.elapsed;
				
				if(!agregada)
				{
					addGraphic(imgBack);
					addGraphic(bar);
					agregada = true;
					car.loop();
				}
				
				if(Input.mousePressed && !pressed)
				{
					pressed = true;
				}
			
				if (Input.mouseReleased)
				{	
					fuelAux = new Fuel(lastX, 555);
					fuel.push(fuelAux);
					add(fuelAux);
					lastX += 10;
					pressed = false;
					counter += 1;
				}
				
				if (fuelTime >= 0.2 && !pressed && counter>0)
				{
					remove(fuel.pop());
					lastX -= 10;
					counter -= 1;
					fuelTime = 0.0;
				}
				
				if (counter >= 49)
				{	
					done = true;
					car.stop();
					car2.play();
				}
			}
			
			
			if (done)
			{
				FP.world = new FinalScene();
				removeAll();
				
			}
			
			
			super.update()
		}
		
	}

}